package db;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;

public class Roles {
	
	// set connection to DBHelper
	DBHelper helper = new DBHelper();
	
	private PreparedStatement roleDataStatement;
	
	//Declaring role data  variables
    
    //role name 
    private String roleName;
    
    //role id  
    private int roleId;
    
    
    
    /**
     * Creates role data object that contains the following
     * @param roleName
     * @param roleId
    */
    
    /**
     * Generate Constructor
     */
    
    public Roles(
    		 String roleName
    	     ,int roleId
    	     ) {
    	
    	this.roleName = roleName;
   	 	this.roleId = roleId;
   	 	
    }

    public Roles() {

	}

	/** Returns the role data */
	public ArrayList<Roles> getRoleInfo (){
		ResultSet rs = null;
		Connection conn = helper.connection();
		ArrayList<Roles> roleInfoData = new ArrayList<Roles>();
		try {
			System.out.println("start role query");
			
			roleDataStatement = conn
					.prepareStatement(DBHelper.roleDataStatement);
			
			rs = roleDataStatement.executeQuery();
			while (rs.next()){
				System.out.println("display  role query");				
			
					//idRoleTypes, roleName
				Roles newRoleData = new Roles(rs.getString("roleName"),rs.getInt("idRoleTypes"));
				roleInfoData.add(newRoleData);
			}
			rs.close();
	}
		
		catch (Exception e){
			System.out.println("Error in getRoleInfo: "+e.getClass().getName()+":"+ e.getMessage());
		    } finally {
		    	DBHelper.disconnect(rs, roleDataStatement, conn);
		    }
		System.out.println("end role query");
		return roleInfoData;
	}

	public String getRoleName() {
		return roleName;
	}



	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}



	public int getRoleId() {
		return roleId;
	}



	public void setRoleId(int roleId) {
		this.roleId = roleId;
	}

}
